package com.example.wifidirect;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.text.method.ScrollingMovementMethod;
import android.widget.TextView;

public class TextActivity extends Activity {
	
	TextView text ;
	String filePath;
	
	@Override
	public void onCreate(Bundle savedInstanceState){
		super.onCreate(savedInstanceState);
		Intent intent = getIntent();
		filePath = intent.getStringExtra("filePath");
		
		setContentView(R.layout.activity_text);
		text = (TextView)findViewById(R.id.show_text);
		text.setMovementMethod(ScrollingMovementMethod.getInstance());
		
		File fi = new File(filePath);
		if(!fi.exists()){
			try {
				fi.createNewFile();
			} catch (IOException e) {			
				e.printStackTrace();
			}
		}
		try {
			BufferedReader br = new BufferedReader(new FileReader(fi));
			String line = null;
			while((line=br.readLine()) != null){
				text.append(line+'\n');
			}
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}
